package com.atguigu.spzx.common.handler;


import com.atguigu.spzx.model.vo.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {


    /**
     * 当目标接口抛出Exception类型的异常时，就会执行到这个异常处理器方法
     * @param exception
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public Result handleException(Exception exception){
        return Result.build(null, 201,exception.getMessage());
    }


    @ExceptionHandler(value = RuntimeException.class)
    public Result handleException(RuntimeException exception){
        return Result.build(null, 201,exception.getMessage());
    }


    @ExceptionHandler(value = ArithmeticException.class)
    public Result handleException(ArithmeticException exception){
        return Result.build(null, 201,exception.getMessage());
    }

}
